﻿using JNPF.Basics.Models.PlatForm.Entities;
using JNPF.Data;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace JNPF.Basics.Logic.PlatForm.CommonFields
{
    /// <summary>
    /// 常用字段
    /// 版 本：V3.0.0
    /// 版 权：引迈信息技术有限公司（https://www.jnpfsoft.com）
    /// 作 者：JNPF开发平台组
    /// 日 期：2018-11-29
    /// </summary>
    public class CommonFieldsService : DataFactory, CommonFieldsIService
    {
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task<int> Create(ComFieldsEntity entity)
        {
            using (var db = this.Basic)
            {
                return await db.InsertAsync(entity);
            }
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task<int> Delete(ComFieldsEntity entity)
        {
            using (var db = this.Basic)
            {
                return await db.DeleteAsync(entity);
            }
        }
        /// <summary>
        /// 信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<ComFieldsEntity> GetInfo(string id)
        {
            using (var db = this.Basic)
            {
                return await db.GetEntityAsync<ComFieldsEntity>(m => m.Id == id);
            }
        }
        /// <summary>
        /// 列表
        /// </summary>
        /// <returns></returns>
        public async Task<List<ComFieldsEntity>> GetList()
        {
            using (var db = this.Basic)
            {
                return await db.GetIQueryable<ComFieldsEntity>().OrderBy(o => o.SortCode).ToListAsync();
            }
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task<int> Update(ComFieldsEntity entity)
        {
            using (var db = this.Basic)
            {
                return await db.UpdateAsync(entity);
            }
        }
    }
}
